Skip to content

Remove fixed display limit - #11963

Merged
dhalbert merged 43 commits into
adafruit:mainfrom
tannewt:infinite_displays
Dec 4, 2026
Merged

dhalbert merged 43 commits into
adafruit:mainfrom
tannewt:infinite_displays

Conversation

@tannewt

@tannewt tannewt commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Displays and display buses are now allocated in two parts. First, the core state struct is allocated outside the VM heap so that it works when the VM is not running. Second, a proxy allocation is done within the VM to tie the display's lifetime to the VM. The proxy also holds a second _vm_t state struct that holds VM pointers so they get collected.

Some signal lines like DC and backlight used to be provided as native pins. Now they also take in DigitalInOut and PWMOut where appropriate so that they can be shared across multiple displays and buses. deinit()ing the display or bus will not deinit the shared objects. It is assumed that garbage collection will do it when appropriate.

One display can be designated as the primary via
supervisor.runtime.display. This applies a primary designation to the display bus it uses as well. These are then (usually) preserved when the VM stops using stop_vm. During stop_vm, some objects like PWMOut for backlight will be moved internal to the display so they keep working. When the VM runs again, start_vm is called. This allows the preserved display and bus to move the internal objects like PWMOut back to the VM heap so it is shareable with other displays.

Small builds have a "simple" lifetime where user constructed displays are not kept outside the VM and the proxy mechanics are not compiled in. This saves space but still allows for multiple displays while the VM is running. board displays are still outlive the VM and can be used as the primary.

Board initiated displays are also not deinit() when the VM stops. They do not move objects because they are constructed fully outside of the VM.

release_displays() still exists but is deprecated. It will deinit all board displays and the primary display. It will not deinit user created displays that are not the primary. Code should be changed to explicitly deinit the display it wants to. For example, board.DISPLAY.deinit() will allow one to re-init the board's display.

Fixes #1760. Related to #8675, #10791, #6395 and #7472.

@tannewt
tannewt force-pushed the infinite_displays branch 2 times, most recently from 627c41d to 9e80f03 Compare November 25, 2026 22:41
Displays and display buses are now allocated in two parts. First, the
core state struct is allocated outside the VM heap so that it works when
the VM is not running. Second, a proxy allocation is done within the VM
to tie the display's lifetime to the VM. The proxy also holds a second
_vm_t state struct that holds VM pointers so they get collected.

Some signal lines like DC and backlight used to be provided as native
pins. Now they also take in DigitalInOut and PWMOut where appropriate so
that they can be shared across multiple displays and buses. deinit()ing
the display or bus will not deinit the shared objects. It is assumed
that garbage collection will do it when appropriate.

One display can be designated as the primary via
`supervisor.runtime.display`. This applies a primary designation to the
display bus it uses as well. These are then preserved when the VM stops
using `stop_vm`. During `stop_vm`, some objects like PWMOut for
backlight will be moved internal to the display so they keep working.
When the VM runs again, `start_vm` is called. This allows the preserved
display and bus to move the internal objects like PWMOut back to the VM
heap so it is shareable with other displays.

Board initiated displays are also not deinit() when the VM stops. They
do not move objects because they are constructed fully outside of
the VM.

`release_displays()` still exists but is deprecated. It will deinit all
board displays and the primary display. It will not deinit user created
displays that are not the primary. Code should be changed to explicitly
deinit the display it wants to. For example, `board.DISPLAY.deinit()`
will allow one to re-init the board's display.

Fixes micropython#1760. Related to micropython#8675, micropython#10791, micropython#6395 and micropython#7472.
This reverts the epaper sequence changes and adds const display ops
tables. It also reverts the nlr guards that were overly cautious.
@tannewt

tannewt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Ok @dhalbert. I think this is ready for review. The CI passes. I'm sure there are bugs but this gets us pretty far and bug fixes will be easier to review as separate PRs. I tested on T keyboard display with only one board.DISPLAY set and other three init at runtime. One of them is then set as primary.

@tannewt
tannewt marked this pull request as ready for review December 1, 2026 23:57
If a primary display can't live without the VM it will be deinit when
the vm is stopped. This allows primary displays when doing "simple"
lifetime while the VM is active.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massive amount of work, thanks. Fortunately the board stuff is mostly boilerplate.

Most of my comments are about terminology, but a few code questions.

I have yet to test on hardware, and will do that.

Comment thread py/circuitpy_mpconfig.mk Resolved
Comment thread shared-bindings/busdisplay/BusDisplay.c Resolved
Comment thread shared-bindings/busdisplay/BusDisplay.c Resolved
Comment thread shared-bindings/busdisplay/BusDisplay.c Resolved
Comment thread shared-bindings/supervisor/Runtime.c Resolved
Comment thread shared-module/busdisplay/__init__.c Resolved
Comment thread shared-module/displayio/lifetime.h Resolved
Comment thread ports/espressif/supervisor/port.c Resolved
@mikeysklar

mikeysklar commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

This looks quite good.

Tested with smitka's cp-desktop-lab simulator 22 boards with this PR and compared it to main.

Each board creates two ST7789s and an SSD1306 at runtime next to board.DISPLAY, makes one ST7789 primary, then reloads twice.

Check This PR main
board.DISPLAY exists and is primary at start 22/22 22/22
3 displays created at runtime 22/22 22/22
ST7789 subclass set as supervisor.runtime.display 22/22 0/22
That display survives reload as primary 22/22 0/22
Non-primary display released at reload 22/22 0/22
board.DISPLAY alive and can be primary again 22/22 22/22

Boards: clue, funhouse, macropad, magtag, pybadge, pygamer, pyportal, circuitplayground, circuitplayground_bluefruit, feather, fruitjam, matrixportal, metro, metro_m4_airlift, metro_rp2350, pico, picopad, propmaker, qtpy, trellis_m4, trinket

Two things:

  • After supervisor.runtime.display.deinit() on a user-set primary, supervisor.runtime.display is None and doesn't fall back to board.DISPLAY. Is that intended?

  • In the case of the Newxie Nine - Multiple displays that share a D/C pin need one DigitalInOut passed to each FourWire. Those displays can't be made primary, and the error is a ValueError with no message. I hit this simulating a nine-display board with a shared D/C line.

@tannewt

tannewt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author
  • After supervisor.runtime.display.deinit() on a user-set primary, supervisor.runtime.display is None and doesn't fall back to board.DISPLAY. Is that intended?

Yes, that is intended. We now want displays to be explicitly opted into being the primary. I changed this because some folks have complained about the repl showing on their screen when they don't want it to.

  • In the case of the Newxie Nine - Multiple displays that share a D/C pin need one DigitalInOut passed to each FourWire. Those displays can't be made primary, and the error is a ValueError with no message. I hit this simulating a nine-display board with a shared D/C line.

Ok, I'll double check this. I was still messing with it a bit in the most recent commit.

@tannewt

tannewt commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Ok, please take another look. I did a bunch of renaming and thinking about the deinit state of displays. They no longer pretend to be None. Instead, they eval as False when deinit.

mikeysklar
mikeysklar previously approved these changes Dec 3, 2026

@mikeysklar mikeysklar left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested 9c3c554 on 22 board files: all pass, shared D/C included.

You will need to resolve the zephyr CI issues.

nit: setting a deinited display says it isn't AnyDisplay.

Check This PR main
board.DISPLAY exists and is primary at start 22/22 22/22
3 displays created at runtime 22/22 22/22
ST7789 subclass set as supervisor.runtime.display 22/22 0/22
That display survives reload as primary 22/22 0/22
Non-primary display released at reload 22/22 0/22
board.DISPLAY alive and can be primary again 22/22 22/22

@mikeysklar
mikeysklar dismissed their stale review December 3, 2026 15:13

Holding off until the zephyr display tests pass.

@mikeysklar mikeysklar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zephyr display tests fail on 9c3c554 (they passed on dad2729). These three changes fix both causes in cp-desktop-lab, and the 22 board sweep still passes 9/9.

Comment thread shared-module/fourwire/FourWire.c Resolved
Comment thread shared-module/displayio/proxy.c Resolved

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. This is a small batch of comments, based on my own follow-ups. I will work on a larger one with things that Claude noticed.

I marked some renaming things, and one thing about the camera code.

A new more general issue Claude noticed while testing the camera code is that invoking board.I2C() in one VM run, and then inovking busio.I2C(board.SCL, board.SDA) after a soft reload, in the next VM, fails with ValueError: SCL in use. On 10.3.2 and on main this does not fail. This is true on plain old boards liked Metro ESP32-S3, not just a camera board. Same kind of problem with board.SPI() and board.UART() -- they live past the end of the VM.

Comment thread shared-module/displayio/lifetime.h Resolved
dhalbert and others added 6 commits December 4, 2026 13:57
Without it, the board framebuffer is treated as deinited, so it never gets
on_vm_start and its audio sample is not GC-rooted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed constructor leaked its pins, timer and framebuffer: the
deinited check looked at Protomatter's rgbPins, which is not set yet, so
deinit() returned early. Use a deinited flag, as FourWire and ParallelBus
do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LVGL now drives several displays. Only one zephyr_display.Display can
exist because there is only one zephyr,display device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannewt and others added 2 commits December 4, 2026 11:06
BusDisplay.backlight returned the backlight a display built from
backlight_pin. That object is stored in the display's own storage, which
is freed with the display, so a Python reference to it could later point
at freed memory. Passing it to another display also let deinit of the
first display turn off the second display's backlight.

Return None for such a backlight. Backlights passed in as backlight are
still returned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannewt

tannewt commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

FYI Dan's fixes are PRed to this branch here: tannewt#28

dhalbert and others added 3 commits December 4, 2026 14:18
A camera on a heap busio.I2C leaked an I2C peripheral at each reload.
The bus's finaliser could run before the camera's, and ESP-IDF won't
delete a bus that still has the camera's device on it. Mark the Camera
type MP_TYPE_FLAG_FINALISER_FIRST so it releases the device first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes for "Remove fixed display limit"

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude wrote this:

Two small items from re-reviewing 4a4128a. Tested on native_sim, including ASAN, and built for Fruit Jam.

Comment thread shared-bindings/busdisplay/BusDisplay.c Resolved
tannewt and others added 3 commits December 4, 2026 12:36
Co-authored-by: Dan Halbert <halbert@adafruit.com>
The other BusDisplay getters raise after deinit, but backlight returned
None. Check for deinit as they do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Dan Halbert <halbert@halwitz.org>
Raise when reading BusDisplay.backlight after deinit

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE. Yay! Thanks @tannewt!!

@dhalbert
dhalbert merged commit 07a0e1c into adafruit:main Dec 4, 2026
723 checks passed
@mikeysklar

mikeysklar commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

@dhalbert @tannewt -

Tested the PR artifacts on the following farm hardware with no regressions.

Board Port Flash Result
Metro RP2040 rp2040 UF2 PASS
Metro RP2350 rp2350 UF2 PASS
Fruit Jam rp2350 UF2 PASS
Pico rp2040 UF2 PASS
Pico W rp2040 UF2 PASS
Pico 2 rp2350 UF2 PASS
Pico 2 W rp2350 UF2 PASS
Feather RP2040 RFM rp2040 UF2 PASS
Metro M4 AirLift Lite samd51 SWD PASS
Metro M0 Express samd21 SWD PASS (no persist by config)
Feather nRF52840 nrf SWD PASS
Feather STM32F405 stm SWD PASS
Metro ESP32-S2 espressif esptool+UF2 PASS
Metro ESP32-S3 espressif esptool+UF2 PASS
MagTag 2.9 (e-ink) espressif esptool PASS
MEMENTO (TFT) espressif esptool+UF2 PASS
ESP32-P4X Function EV espressif esptool PASS
ESP32-C5 DevKitC espressif esptool PASS
Metro M7 1011 mimxrt10xx UF2 PASS
Metro CH32V407 zephyr UF2 flashed, untestable (no busio.SPI)

Exercised without physical panels:

  • display + bus construction, setting a user display as primary
  • primary's bus moved out of the heap at reload
  • non-primary displays released, their pins and SPI freed
  • deinit()
  • built-in displays (MagTag e-ink, MEMENTO TFT) kept as primary across reloads

Test: 2 BusDisplays on spare pins (no panels)

Ctrl-D reload. Pass = primary survives with its pins, other display's pins freed, deinit frees rest; built-in display stays primary.

vegardw added a commit to vegardw/circuitpython that referenced this pull request Dec 6, 2026
adafruit#11963 removed allocate_display_bus(), allocate_display() and
displays[]. Build the board's parallel bus and display in static
objects with displayio_native_init(), as the other boards now do, and
make the display the primary one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants